package fr.expdev.bndd;

import fr.expdev.bndd.data.Post;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;

public class DetailPost extends Activity {
	
	private AppContext _appContext = AppContext.getAppContext();
	
	private Post _post;
	
	private TextView _title;
	private WebView _view;
	private Button _next;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.detail_post);
        
        int postNumber = getIntent().getIntExtra("post_number", -1);
        if (postNumber > -1) {
        	_post = _appContext.posts.get(postNumber);
        }

        _title = ((TextView)findViewById(R.id.detail_post_title));
        _view = ((WebView)findViewById(R.id.detail_post_excerpt));
        _next = ((Button)findViewById(R.id.detail_post_next));
        
        _view.loadDataWithBaseURL("http://www.experience-developpement.fr/", _post.getExcerpt(), "text/html", "utf-8", "about:blank");
        _title.setText(_post.getTitle());
        _next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(_post.getLink()));
				startActivity(intent);
			}
		});
        
	}

}
